<?php slot('sub', $sub); ?>
<?php  use_javascript('mainFunctions.js');?>
<?php  use_javascript('admins_script.js');?>
<?php  use_javascript('http://www.google.com/jsapi');?>
<?php  use_javascript('http://maps.googleapis.com/maps/api/js?key=AIzaSyA4ORL54bd4TqneYqWekkc22xhZ1T3gH6A&sensor=true');?>
<div class="center">
    <div id="center_conteiner" class="clearfix">
        <div class="center_sub_conteiner">

            <div class="center_block">
                <div class="header_center_block">
                    <span>Create new agent / firm</span>
                    <div class="back_button"><a href="<?php echo url_for('ausers'); ?>">Back</a></div>
                </div>
<div class="aedituser">  
    <div class="aedituser_left"> 
                <div class="center_line" id="add_new_user_title">
                    <div class="field_label">Title</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line" id="add_new_user_first_name">
                    <div class="field_label">First name</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line"  id="add_new_user_last_name">
                    <div class="field_label">Last name</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line" id="add_new_user_email">
                    <div class="field_label">E-mail</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line" id="add_new_user_password">
                    <div class="field_label">Password</div>
                    <input type="password" class="field_input">
                </div>

                <div class="center_line"  id="add_new_user_vpassword">
                    <div class="field_label">Verify Password</div>
                    <input type="password" class="field_input">
                </div>

                <div class="center_line"  id="add_new_user_phone1">
                    <div class="field_label">Phone</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line" id="add_new_user_phone2">
                    <div class="field_label">Phone</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line"  id="add_new_user_fax">
                    <div class="field_label">Fax</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line" id="add_new_user_country">
                    <div class="field_label">Country</div>
                    <select class="field_select">
                        <option selected="selected" value="0">Please select country</option>
                        <?php
                        foreach ($country as $c) {
                            echo '<option value="' . $c->getId() . '">' . $c->getNameEn() . '</option>';
                        }
                        ?>
                    </select>
                </div>

                <div class="center_line" id="add_new_user_city">
                    <div class="field_label">City</div>
                    <select class="field_select"></select>
                </div>

                <div class="center_line"  id="add_new_user_address">
                    <div class="field_label">Address</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line" id="add_new_user_permissions">
                    <div class="field_label">Permissions</div>
                    <select class="field_select">
                        <option selected="selected" value="<?php echo sbValues::TYPE_USER_STANDART; ?>"><?php echo sbValues::TYPE_USER_STANDART; ?></option>
                        <option value="<?php echo sbValues::TYPE_USER_AGENT; ?>"><?php echo sbValues::TYPE_USER_AGENT; ?></option>
                        <option value="<?php echo sbValues::TYPE_USER_FIRM; ?>"><?php echo sbValues::TYPE_USER_FIRM; ?></option>
                        <option value="<?php echo sbValues::TYPE_USER_ADMIN; ?>"><?php echo sbValues::TYPE_USER_ADMIN; ?></option>
                    </select>
                </div>

                <div class="center_line" id="add_new_user_agent_from">
                    <div class="field_label">Agent</div>
                    <select class="field_select">
                        <option selected="selected" value="0">Please select firm</option>
<?php
foreach ($firm as $f) {
    echo '<option value="' . $f->getId() . '">' . $f->getTitle() . '</option>';
}
?>
                    </select>
                </div>

                <div class="center_line" id="add_new_user_status">
                    <div class="field_label">Status</div>
                    <select class="field_select">
                        <option value="1">active</option>
                        <option value="2">deactivated</option>
                    </select>
                </div>

                <div class="center_line" id="add_new_user_commisions">
                    <div class="field_label">Commissions %</div>
                    <input type="text" class="field_input">
                </div>

                <div class="center_line">
                    <div class="field_button_positive" id="add_new_user_btn_save">Save</div>
                    <div class="field_button_negative" id="add_new_user_btn_cancel"><a href="<?php echo url_for('ausers'); ?>">Cancel</a></div>
                </div>
    </div>
    <div class="aedituser_right" id="agents_map"></div>
     <input type="hidden" name="lat" id="lat" value="">
      <input type="hidden" name="lng" id="lng" value="">
   <script>
$( document ).ready(function() {  

$('#add_new_user_address .field_input').change(function (){
    find_agent_address('#add_new_',false);
});
$('#add_new_user_city .field_select').change(function (){
    find_agent_address('#add_new_',false);
});
$('#add_new_user_country .field_select').change(function (){
    find_agent_address('#add_new_',false);
});
});
</script>
             </div><!--eof aedituser-->
                    
            </div><!--eof center block-->
        </div>
    </div>
</div>

<script  type="text/javascript">
    var country = [];
    var cites = [];

<?php foreach ($city as $c) { ?>
        var temp = {
            id: '<?php echo $c->getId() ?>',
            nameEn: '<?php echo $c->getNameEn() ?>',
            country_id: '<?php echo $c->getCountryId() ?>',
            region_id: '<?php echo $c->getRegionId() ?>'
        };

        cites.push(temp);
<?php } ?>

    $(function() {
        insertCity(0);

        var countryId = 0;
        $('#add_new_user_country select').change(function() {
            countryId = $(this).val();
            insertCity(countryId);
        });
    });

    function insertCity(country_id) {
        $('#add_new_user_city select option').remove();
        var parentSelect = $('#add_new_user_city select');
        var firstOption = '<option value="0">Select city</option>';
        (parentSelect).append(firstOption);

        $.each(cites, function(i, v) {
            if (parseInt(country_id) === 0) {
                    (parentSelect).append('<option value="' + v.id + '">' + v.nameEn + '</option>');
            } else {
                if (parseInt(v.country_id) === parseInt(country_id)) {
                    (parentSelect).append('<option value="' + v.id + '">' + v.nameEn + '</option>');
                }
            }
        });
    }
</script>